Jupyter で Mathematica を使う¶
2024/12/27 滝内
Jupyter を経由して Mathematicaが無料で利用できるとの情報を知った。職場での一括ライセンス更新がなくなってしまったが,再び Mathematicaが利用できるとうれしいので早速導入してみる。
Wolfram Engineを利用するらしい
https://www.wolfram.com/engine/index.php.ja
Wolfram Engineをダウンロードから Windows 10+ を選択。
Wolfram IDがない場合は登録する。私は以前のIDを利用。
ダウンロードしたファイルを実行する。
インストールした後にWolfram Engineを起動して,WindowsにWolfram Engineを設定する。
https://support.wolfram.com/ja/46069
The Wolfram Engine requires one-time activation on this computer.
Visit https://wolfram.com/engine/free-license to get your free license.
Wolfram ID: ***
Password:
Wolfram Engine activated. See https://www.wolfram.com/wolframscript/ for more information.
Wolfram Language 14.1.0 Engine for Microsoft Windows (64-bit)
Copyright 1988-2024 Wolfram Research, Inc.
anacondaを利用しているので,anacondaで gitを install
> conda search git
> conda install git
> conda list
https://github.com/WolframResearch/WolframLanguageForJupyterより gitを使ってファイルを取得。
git clone https://github.com/WolframResearch/WolframLanguageForJupyter.git
WolframLanguageForJupyter フォルダができるのでそこに移動してスクリプトを実行。
> cd .\WolframLanguageForJupyter\
> ./configure-jupyter.wls add
これでJupyter Lab を立ち上げてNew>Notebook kernelをWolfram Language 14.1などにすると Mathematicaのコマンドが実行できる。
Mathematica engine for Jupyter 検索結果からの先人のお知恵やChatGPTのアドバイスを拝借。
Manipulate とAnimate など動的インターフェイスの利用をしたかったが, Manipulateなどでのパラメータを自分で操作することはできないみたい。計算結果の出力は指定しないとImage 形式となるみたい。
Plot[ Sin[x], {x, 0, 2 Pi}]
StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]
ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]
Manipulate[
v =1;
Plot[Sin[2 Pi (x / lambda - v t / lambda)], {x, 0, 2 π}, PlotRange -> {{0, 2 π}, {-1.1, 1.1}},
AxesLabel -> {"x", "Amplitude"}],
{t, 0, 2}, {lambda, 1, 3}
]
Animate[
func := Sin[Sqrt[x^2 + y^2]- t]/Sqrt[x^2 + y^2];
Plot3D[func, {x, -6*Pi, 6*Pi}, {y, -6*Pi, 6*Pi},
BoxRatios -> {1, 1, 0.2}, PlotRange -> {-1, 1}],
{t, 0, Pi}
]
Integrate[Cos[x], x]
%7 // TeXForm
%7 // InputForm
Sin[x]
Solve[x^2 - 2 == 0, x]
%10 // TeXForm
Clear[TeXEq]
SetAttributes[TeXEq, HoldFirst];
TeXEq[expr_, f_: FullSimplify] :=
TeXForm[HoldForm[expr] == f[ReleaseHold[expr]]]
D[Sin[x]^2, x] // TeXEq
Integrate[Sin[x], x] // TeXEq
Integrate[Sin[x]^2, {x, 0, Pi}] // TeXEq